#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@NAME          : admin_route.py
@TIME          : 2025/03/07 10:00:00
@AUTHOR        : chenlip
@VERSION       : 0.1.0
@DESCRIPTION   : 后台管理相关路由
'''
from flask import Blueprint, g, request, render_template, redirect, url_for, flash, session, abort
from flask import current_app, jsonify

from flask_login import login_user, logout_user, login_required, current_user
from flask_jwt_extended import create_access_token, create_refresh_token, jwt_required, get_jwt_identity

from app.service.sse_notifi import NotificationService # 导入sse通知服务
from app.middlewares.error_handler import route_exceptions, BusinessError
from app.common.security import sanitize_input # 导入清洗函数

admin_bp = Blueprint('admin', __name__, url_prefix='/admin')

@admin_bp.route('/adminindex', methods=['GET'])
@login_required
@route_exceptions
def adminindex():
    """ 后台管理首页, 必须登录，且必须时管理员 """
    # print('current_user:', current_user.nickname, current_user.role, current_user.is_admin)
    if current_user.is_admin:
        return render_template('admin/baseadmin.html')
    
    else:
        flash('如需访问后台管理，请使用管理员账户登录！', 'error')
        return redirect(url_for('user.login'))
    